package com.group.utils;

import com.group.result.Result;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.List;
import java.util.StringJoiner;

/**
 * com.gxa.utils
 * User: 恩哲欣
 * Date: 2024/10/22 18:54
 * Motto: Where there is a will, there is a way!
 * Description:
 * Version: V1.0
 */
public class WebUtils {
    public static Result<Object> getResult(BindingResult bindingResult) {
        System.out.println("校验不通过！！！");
        // 获取所有的校验失败的信息
        List<ObjectError> errors = bindingResult.getAllErrors();
        StringJoiner stringJoiner = new StringJoiner(",");
        errors.forEach(objectError -> {
            String message = objectError.getDefaultMessage();
            stringJoiner.add(message);
        });
        return Result.buildFail(50000,stringJoiner.toString());
    }
}
